import { defaultListRequestParams } from '@/config';
import api from '@/services/shop/group-base-management';

export type Department = ShopbaseManagementApi.InfoResponse;

export type ShopbaseManagement = ShopbaseManagementApi.InfoResponse;
export type ShopbaseManagementList = ShopbaseManagementApi.ListResponse;

export const getFilterList = async () => {
  const res = await api.getFilterList();
  return res.data;
};
export const getList = async (params: ShopbaseManagementApi.ListParams) => {
  const res = await api.getList<ShopbaseManagementList>(params);
  const tableData: Requestor.TableFormatedData<ShopbaseManagementList> = {
    data: res.listData,
    current: res.page + 1,
    pageSize: res.limit,
    total: res.count,
    success: res.success,
  };

  return tableData;
};
export const getAllList = async () => {
  const requestParams: ShopbaseManagementApi.ListParams = {
    ...defaultListRequestParams,
    sortField: 'createdAT',
    page: 0,
    limit: 500,
  };
  const res = await api.getList<ShopbaseManagementList>(requestParams);
  return res.listData;
};

export const create = async (params: ShopbaseManagementApi.CreateParams) => {
  const data = await api.create(params);
  return data;
};
export const update = async (params: ShopbaseManagementApi.UpdateParams) => {
  const data = await api.update(params);
  return data;
};
export const remove = async (params: ShopbaseManagementApi.DeleteParams) => {
  const data = await api.remove(params);
  return data;
};
export default {
  getFilterList,
  getList,
  getAllList,
  create,
  update,
  remove,
};
